// Reference for a Google map
var googleMap;

/*******************************************************************************
 * 1. Loads the google map with default coordinates and map type as road
 * 2. Add a event listener and associate with appropriate event
 ******************************************************************************/

function loadMap() {

	var defaultLatlng = new google.maps.LatLng(12.98324167857214,
			79.97104031576797);
	var mapOptions = {
		zoom : 13,
		center : defaultLatlng,
		mapTypeId : google.maps.MapTypeId.ROADMAP
	};

	googleMap = new google.maps.Map(document.getElementById("map_canvas"),
			mapOptions);

	google.maps.event.addListener(googleMap, 'click', function(event) {
		placeMarker(event.latLng,true,"NEW POLICE STATION");
	});
}

/*******************************************************************************
 * 1. Place marker on Google map for mouse click 
 * 2. Enable the drag feature of marker
 * 3. Load the map based on marker position with it as centre
 * @param location of marker, is draggable feature enabled and the marker title
 ******************************************************************************/
function placeMarker(location,isDraggable,markerTitle) {

	var currentLocation=location;
	var infoWindowTitle="url";
	var marker = new google.maps.Marker({
		position : currentLocation,
		map : googleMap,
		title : markerTitle,
		draggable : isDraggable
	});

	if(isDraggable){
		 google.maps.event.addListener(marker, 'dragend', function(event) {
		 currentLocation=event.latLng;
		 infoWindowTitle+=currentLocation;
	});
	}
	googleMap.setCenter(currentLocation);
	loadInfoWindow(marker,infoWindowTitle);
}

/*******************************************************************************
 *@param title,marker
 * Loads the info window with appropriate title while clicking on the marker 
 ******************************************************************************/
function loadInfoWindow(marker,title){

	var infowindow = new google.maps.InfoWindow({
		content : title,
		size : new google.maps.Size(50, 50)
	});

	google.maps.event.addListener(marker, 'click', function() {
		infowindow.open(googleMap, marker);
	});
	
}
	 